using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.CodeDom.Compiler;
using System.Drawing;

namespace Lds.Ward.PhotoDirectory.Logic
{
	public class FamiliesToPhotoBoardPdf : FamiliesToPdf
	{
		public FamiliesToPhotoBoardPdf(IEnumerable<Family> families, string unitName)
			: base(families, unitName, "/XmlToPhotoBoardFO.xslt")
		{
		}

		public static void Convert(IEnumerable<Family> families, string unitName,
			SizeF photoSize, Uri photosDirectory, Stream pdf,
			org.apache.fop.apps.Driver.UpdateStatusCallback update)
		{
			FamiliesToPhotoBoardPdf c = new FamiliesToPhotoBoardPdf(families, unitName);
			c.PhotoSize = photoSize;
			c.Convert(photosDirectory, pdf, update);
		}

		public void Convert(Uri photosDirectory, Stream pdf,
			org.apache.fop.apps.Driver.UpdateStatusCallback update)
		{
			if (pdf == null) throw new ArgumentNullException("pdf");

			using (TempFileCollection tfc = new TempFileCollection())
			{
				tfc.KeepFiles = false;

				XmlReader rawXml = GetXml(photosDirectory, tfc, MediaQuality.Print);
				XmlTextReader fo = GetFO(rawXml);
				FOtoPdf(fo, pdf, update);
			}
		}
	}
}
